package sequentiell;

import java.util.ArrayList;

public class Mesh {
	
	private ArrayList<Integer> elements;
	
	public Mesh(){
		elements = new ArrayList<Integer>();
	}
	
	/**
	 * add a node to the mesh
	 * @param i the node
	 */
	public void add(int i){
		elements.add(i);
	}
	
	/**
	 * remove a node from the mesh
	 * @param i the node
	 * @return true, when node was in the mesh
	 */
	public boolean remove(int i){
		return elements.remove((Object) i);
	}
	
	/**
	 * remove the node at the index i
	 * @param i the index of the node, which will be removed
	 * @return the node, which was removed
	 */
	public int getAndRemove(int i){
		return elements.remove(i);
	}
	
	/**
	 * get the node at the index i
	 * @param i the index of the node
	 * @return the node at index i
	 */
	public int get(int i){
		return elements.get(i);
	}
	
	/**
	 * 
	 * @return the size of the mesh
	 */
	public int size(){
		return elements.size();
	}
	
	/**
	 * 
	 * @return a string-version of the mesh
	 */
	public String toString(){
		String s = "";
		for(int i=0;i<elements.size();i++)
			if(i==0)
				s = s+get(i);
			else s = s+", "+get(i);
		return s;
	}
	/**
	 * if the meshes have the same elements, this method returns true
	 * @param m
	 * @return
	 */
	public boolean equal(Mesh m){
		boolean check=true;
		if(m.size() != this.size())
			return false;
		for(int i=0;i<this.size();i++){
			if(m.get(i) != this.get(i))
				check=false;
		}
		
		return check;
	}
	
	/**
	 * if the mesh contains e, this method returns true
	 * @param e
	 * @return
	 */
	public boolean contains(int e){
		boolean check=false;
		for(int i=0;i<this.size();i++)
			if(this.get(i)==e )
				check=true;
		return check;
	}
}
